﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NextCMS.Models;

public partial class ContentEdit : WebadminBasePage
{
    int Id, PageModuleId = 0;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        int.TryParse(Convert.ToString(Request.QueryString["Id"]), out Id);
        int.TryParse(Convert.ToString(Request.QueryString["PageModuleId"]), out PageModuleId);
        if (Id > 0)
        {

            PageModulesHelper pmc = new PageModulesHelper();
            PageModuleModel pmm = pmc.GetById(PageModuleId);
            PageContentsHelper cc = new PageContentsHelper();
            PagesHelper pc = new PagesHelper();
            TemplatesHelper mpc = new TemplatesHelper();
            PageModel pm=pc.GetByPageIdLanguageId(pmm.PageId,UserLanguageId);
            PageContentModel mp = cc.GetById(Id, UserLanguageId);
            TemplateModel mpm = mpc.GetById(pm.MasterPageId);

            SiteResourcesHelper srh = new SiteResourcesHelper();
            SiteResourceModel srm= srh.GetById(mpm.WebResourceId);
            Session["FileManager"] = "/Templates/" + srm.FolderName + "/";
            elm1.FilebrowserBrowseUrl = "FileManager/Default.aspx?SessionId=" + Session.SessionID;
            
            if (Request.Form["elm1"] != null)
            {
                mp.Content = Convert.ToString(Request.Form["elm1"]);
                SavePage(mp);

                Page.ClientScript.RegisterStartupScript(Page.GetType(), "df", "self.close();",true);
            }
            else
            {

                elm1.Text = mp.Content;
            }



           
            elm1.CKEditorInstanceEventHandler = new System.Collections.Generic.List<object>();
            elm1.CKEditorInstanceEventHandler.Add(new object[] { "instanceReady", "function (evt) { ExecuteCommand('maximize');}" });


        }
    }


    void SavePage(PageContentModel cModel)
    {
        PageContentsHelper pcc = new PageContentsHelper();
        pcc.Edit(cModel);
    }
}